#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'Michael Liao'

'''
Models for user, blog, comment.
'''

import time, uuid

from transwarp.db import next_id
from transwarp.orm import Model, StringField, BooleanField, FloatField, TextField, IntegerField

def next_id():
    return '%015d%s000' % (int(time.time() * 1000), uuid.uuid4().hex)

class User(Model):
    __table__ = 'users'

    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')
    email = StringField(updatable=False, ddl='varchar(50)')
    password = StringField(ddl='varchar(50)')
    admin = BooleanField()
    name = StringField(ddl='varchar(50)')
    image = StringField(ddl='varchar(500)')
    created_at = FloatField(updatable=False, default=time.time)

class Blog(Model):
    __table__ = 'blogs'

    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')
    user_id = StringField(updatable=False, ddl='varchar(50)')
    user_name = StringField(ddl='varchar(50)')
    user_image = StringField(ddl='varchar(500)')
    name = StringField(ddl='varchar(50)')
    summary = StringField(ddl='varchar(200)')
    content = TextField()
    created_at = FloatField(updatable=False, default=time.time)

class Comment(Model):
    __table__ = 'comments'

    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')
    blog_id = StringField(updatable=False, ddl='varchar(50)')
    user_id = StringField(updatable=False, ddl='varchar(50)')
    user_name = StringField(ddl='varchar(50)')
    user_image = StringField(ddl='varchar(500)')
    content = TextField()
    created_at = FloatField(updatable=False, default=time.time)

class Menu(Model):
    __table__ = 'menu'
    id = IntegerField(primary_key=True)
    parentid = IntegerField()
    name = TextField()
    url  = TextField()
    levlel = IntegerField()
    display = IntegerField()
    showorder = IntegerField()
####################################################
class Xyfx_config(Model):
    __table__ = 'xyfx_config'
    id = IntegerField(primary_key=True)
    name = TextField()
    type   = IntegerField()
    filename = TextField()
    path  = TextField()
    commets   = TextField()

class Xyfx_db_config(Model):
    __table__ = 'xyfx_db_config'
    id = IntegerField(primary_key=True)
    configid = IntegerField()
    serverip = TextField()
    username = TextField()
    password = TextField()
    dbname = TextField()

class Xyfx_remote(Model):
    __table__ = 'xyfx_remote'
    id = IntegerField(primary_key=True)
    serverip = TextField()
    port = IntegerField()
    username = TextField()
    password = TextField()

#####################################################
class Ljt_taskinfo(Model):
    __table__ = 'ljt_taskinfo'
    id = IntegerField(primary_key=True)
    detail_file_name = TextField()
    detail_file_path = TextField()
    create_time = TextField()
    contract_num = IntegerField()
    state = IntegerField()

